package com.gitee.srurl.system.params;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author zxw
 * @date 2023/4/29 7:07
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GenerateShortUrlParams implements Serializable {

    @Serial
    private static final long serialVersionUID = 7376833169975819590L;

    /**
     * 生成的url
     */
    @NotBlank(message = "待生成url不能为空")
    private String url;

    /**
     * 访问多少次后失效
     * 默认不限制次数
     */
    private Long times;

    /**
     * 过期时间
     * 默认半年后过期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime expireTime;

    /**
     * 更新访问次数 默认为true更新
     */
    private Boolean updateTimes;
}
